//
//  CQBaseCardCollectionViewCell.swift
//  TSListDemo
//
//  Created by qian on 2020/11/6.
//  Copyright © 2020 dvlproad. All rights reserved.
//

import UIKit
import SnapKit

class CQBaseCardCollectionViewCell: UICollectionViewCell {
    var originalCenter: CGPoint?
    var originalFrame: CGRect?
    var currentAngle: CGFloat?
    var indexPathItem = 0
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    
    override func apply(_ layoutAttributes: UICollectionViewLayoutAttributes) {
        super.apply(layoutAttributes)
        self.layer.zPosition = CGFloat(layoutAttributes.zIndex)
    }
    
    func resetlayoutWithOffset(_ offset: CGPoint = .zero, collectionViewLayout: CQTBaseCardCollectionViewFlowLayout) {
        if indexPathItem == 0 {
            debugPrint("第一张图片使用拖动pan手势，肯定不会执行到此方法中")
            return
        }
        
        let cellIndexPathItem = indexPathItem
        let cellCenterX = collectionViewLayout.getCellCenterX()
        let cellScale: CGFloat = collectionViewLayout.getCellScale(itemIndex: cellIndexPathItem, offset: offset)
        let cellCenterY: CGFloat = collectionViewLayout.getLastCellCenterY(itemIndex: cellIndexPathItem, scale: cellScale)
        let cellCenterPoint: CGPoint = CGPoint.init(x: cellCenterX, y: cellCenterY)
//        let cellCenterPoint: CGPoint = self.originalCenter;
        
        self.center = cellCenterPoint
        self.transform = CGAffineTransform(scaleX: cellScale, y: cellScale)
    }
}
